<template>
  <div class="login-phone">
    <el-form label-width="64px" :rules="rules" :model="phoneAccount" size="large" ref="formRef">
      <el-form-item label="手机号" prop="phoneNumber">
        <el-input type="text" v-model="phoneAccount.phoneNumber" />
      </el-form-item>
      <el-form-item label="验证码" prop="authCode">
        <div class="get-authcode">
          <el-input type="password" v-model="phoneAccount.authCode" />
          <el-button type="primary" class="get-btn">获取验证码</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { rules } from '../../config/phoneConfig'
import { ElForm } from 'element-plus'

export default defineComponent({
  name: 'LoginPhone',
  setup() {
    const phoneAccount = reactive({
      phoneNumber: '',
      authCode: ''
    })
    const formRef = ref<InstanceType<typeof ElForm>>()
    const login = () => {
      formRef.value?.validate((valid) => {
        if (valid) {
          console.log('执行手机号登录逻辑')
        }
      })
    }
    return {
      phoneAccount,
      rules,
      formRef,
      login
    }
  }
})
</script>

<style scoped lang="less">
.get-authcode {
  display: flex;
  .get-btn {
    margin-left: 8px;
  }
}
</style>
